package com.wuyb;

import com.corundumstudio.socketio.SocketIOServer;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

import java.util.Set;
import java.util.stream.Collectors;

@SpringBootApplication
@MapperScan("com.wuyb.mapper")
@EnableRedisHttpSession
@Slf4j
public class MeetingApplication implements CommandLineRunner {

    @Resource
    private SocketIOServer socketIOServer;

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public static void main(String[] args) {
        SpringApplication.run(MeetingApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {
        socketIOServer.start();
        log.info("Socket.io启动");

        // 对每个Key去除前缀 meeting_system 长度为15
        Set<String> collect = redisTemplate.keys("*").stream().map(x -> x.substring(15)).collect(Collectors.toSet());
        if (!collect.isEmpty()) {
            Long delete = redisTemplate.delete(collect);
            log.info("Redis缓存清空");
        }
    }
}
